/// <reference types="vitest" />
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    VitePWA({
      registerType: 'autoUpdate',
      devOptions: {
        enabled: true
      },
      manifest: {
        name: 'FastAPI Platform',
        short_name: 'FastAPI',
        description: '基于RBAC的权限管理系统 + DailyHotApi热点服务',
        theme_color: '#61dca3',
        icons: [
          {
            src: 'src/assets/logo.png',
            sizes: '192x192',
            type: 'image/png'
          },
          {
            src: 'src/assets/logo.png',
            sizes: '512x512',
            type: 'image/png'
          }
        ]
      }
    })
  ],
  server: {
    host: true,
    port: 5202,
    strictPort: false,
    hmr: {
      host: 'localhost',
      port: 5202,
      protocol: 'ws',
      timeout: 30000,
      overlay: true,
      clientPort: 5202
    },
    watch: {
      // 减少文件监听的频率，避免过度触发热更新
      usePolling: false,
      interval: 1000
    },
    proxy: {
      '/api': {
        target: 'http://localhost:8989',
        changeOrigin: true,
        secure: false
      }
    }
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          vendor: ['react', 'react-dom'],
          antd: ['antd'],
          charts: ['echarts-for-react'],
          animation: ['framer-motion', 'gsap']
        }
      }
    },
    chunkSizeWarningLimit: 1000
  },
  css: {
    postcss: {
      plugins: [
        require('autoprefixer'),
      ],
    },
  },
})